package com.gonsin.project.creator.create;

public interface IJavaScriptBinder {

    /**
     * javascript脚本前置内容
     */
    String JS_PREFIX = "" +
            "function input(message, defaultValue) {" +
            "   return java.input(message, defaultValue)" +
            "}" +
            "function output(message){" +
            "   java.output(message)" +
            "}" +
            "function format(f, time){" +
            "   return java.format(f, time);" +
            "}" +
            "function go(o){" +
            "   return java.go(o);" +
            "}" +
            "function save(o){" +
            "   return java.save(o);" +
            "}" +
            "function reload(o){" +
            "   var json = java.reload(o);" +
            "   return JSON.parse(json);" +
            "}" +
            "function camelToUnderline(message){" +
            "   return java.camelToUnderline(message)" +
            "}" +
            "function underlineToCamel(message){" +
            "   return java.underlineToCamel(message)" +
            "}" +
            "function javaType2dbType(message){" +
            "   return java.javaType2dbType(message)" +
            "}" +
            "function dbColumn(message){" +
            "   return java.dbColumn(message)" +
            "}" +
            "function javaType2objectType(message){" +
            "   return java.javaType2objectType(message)" +
            "}" +
            "function firstLowercase(message){" +
            "   return java.firstLowercase(message)" +
            "}" +
            "function time(){" +
            "   return java.time()" +
            "}" +
            "function firstUppercase(message){" +
            "   return java.firstUppercase(message)" +
            "}" +
            "function isTrue(b){" +
            "   if(b == 'true' || b == 'y' || b == 'Y'){" +
            "       return true;" +
            "   }" +
            "   if(b == 'false' || b == 'n' || b == 'N'){" +
            "       return false;" +
            "   }" +
            "   return b;" +
            "}\n" +
            "";


    /**
     * 输入数据
     */
    default Object input(String message){
        return input(message, null);
    }
    Object input(String message, Object defaultValue);


    /**
     * 打印数据
     * @param message
     */
    void output(Object message);


    /**
     * 格式化时间
     */
    String format(String format, Long time);


    /**
     * 返回当前时间戳
     */
    Long time();


    /**
     * 驼峰命名 转下划线
     */
    String camelToUnderline(String message);


    /**
     * 驼峰命名 转下划线
     */
    String underlineToCamel(String message);


    /**
     * 驼峰命名 转首字母小写
     */
    String firstLowercase(String message);


    /**
     * 驼峰命名 转首字母大写
     */
    String firstUppercase(String message);


    /**
     * java类型转数据库类型
     */
    String javaType2dbType(String type);


    /**
     * java类型转对象类型
     */
    String javaType2objectType(String type);


    /**
     * 如果name属于mysql保留关键词，则会在前面加上 gs_
     */
    String dbColumn(String name);


    /**
     * 生成代码
     */
    void go(Object o) throws Exception;

    /**
     * 保存输入
     */
    void save(Object o) throws Exception;

    /**
     * 读取
     */
    String reload(Object defaultValue) throws Exception;


}
